<?php

namespace app\admin\model\service\shop;

use think\Model;
use traits\model\SoftDelete;

class Shop extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'service_shop';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'to_shop_text',
        'type_text',
        'state_text'
    ];
    

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    
    public function getToShopList()
    {
        return ['0' => __('To_shop 0'), '1' => __('To_shop 1')];
    }

    public function getTypeList()
    {
        return ['0' => __('Type 0'), '1' => __('Type 1')];
    }

    public function getStateList()
    {
        return ['0' => __('State 0'), '1' => __('State 1')];
    }


    public function getToShopTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['to_shop']) ? $data['to_shop'] : '');
        $list = $this->getToShopList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStateTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['state']) ? $data['state'] : '');
        $list = $this->getStateList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getLogoImageAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['logo_image']) ? $data['logo_image'] : '');
        if ($value) {
            return cdnurl($value, true);
        }
        return '';
    }
    
    public function getFrontImageAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['front_image']) ? $data['front_image'] : '');
        if ($value) {
            return cdnurl($value, true);
        }
        return '';
    }
    
    public function getOppositeImageAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['opposite_image']) ? $data['opposite_image'] : '');
        if ($value) {
            return cdnurl($value, true);
        }
        return '';
    }
    
    public function getLicenseImageAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['license_image']) ? $data['license_image'] : '');
        if ($value) {
            return cdnurl($value, true);
        }
        return '';
    }

}
